package com.lkd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.dto.SkuClassDto;
import com.lkd.entity.SkuClass;
import com.lkd.mapper.SkuClassMapper;
import com.lkd.result.PageBean;
import com.lkd.service.SkuClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SkuClassServiceImpl implements SkuClassService {

    @Autowired
    private SkuClassMapper skuClassMapper;


    @Override
    public PageBean findByPage(SkuClassDto skuClassDto) {
        //开启分页
        PageHelper.startPage(skuClassDto.getPageIndex(), skuClassDto.getPageSize());

        //执行查询
        List<SkuClass> skuClassList = skuClassMapper.findList(skuClassDto);
        Page<SkuClass> page = (Page<SkuClass>) skuClassList;

        //返回结果
        PageBean<SkuClass> pageBean = new PageBean<>();
        pageBean.setPageIndex(page.getPageNum());
        pageBean.setPageSize(page.getPageSize());
        pageBean.setTotalPage((long)page.getPages());
        pageBean.setTotalCount(page.getTotal());
        pageBean.setCurrentPageRecords(page.getResult());

        return pageBean;
    }

    @Override
    public Boolean save(SkuClass skuClass) {
        return skuClassMapper.save(skuClass);
    }

    @Override
    public SkuClass findById(Long classId) {
        return skuClassMapper.findById(classId);
    }

    @Override
    public Boolean update(SkuClass skuClass) {
        return skuClassMapper.update(skuClass);
    }

    @Override
    public Boolean deleteById(Long classId) {
        return skuClassMapper.deleteById(classId);
    }
}
